package rs.dalao.syc.doctor.all.dao.persist.repository.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import rs.dalao.syc.doctor.all.dao.persist.mapper.DoctorCredentialMapper;
import rs.dalao.syc.doctor.all.dao.persist.mapper.DoctorMapper;
import rs.dalao.syc.doctor.all.dao.persist.repository.IDoctorCredentialRepository;
import rs.dalao.syc.doctor.all.pojo.entity.Doctor;
import rs.dalao.syc.doctor.all.pojo.entity.DoctorCredential;
import rs.dalao.syc.doctor.all.pojo.param.DoctorCredentialParam;
import rs.dalao.syc.doctor.all.pojo.vo.DoctorCredentialVO;

import javax.print.Doc;

@Repository
public class DoctorCredentialRepositoryImpl implements IDoctorCredentialRepository {
    @Autowired
    private DoctorCredentialMapper doctorCredentialMapper;
    @Autowired
    private DoctorMapper doctorMapper;

    //根据用户id遍历用户的证书信息


    //新增医生证书信息
    @Override
    public int insert(DoctorCredential doctorCredential) {
       return doctorCredentialMapper.insert(doctorCredential);
    }

    //修改医生的证书信息
    @Override
    public int updateById(DoctorCredentialParam doctorCredentialParam,Long id) {
        QueryWrapper<DoctorCredential> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        DoctorCredential doctorCredential = new DoctorCredential();
        BeanUtils.copyProperties(doctorCredentialParam,doctorCredential);
        return doctorCredentialMapper.update(doctorCredential,queryWrapper);
    }

    //根据医生id查询医生证书信息
    @Override
    public DoctorCredentialVO selectById(Long id) {
        return doctorCredentialMapper.selectById(id);
    }

    //根据id修改医生的角色
    @Override
    public int updateRoleById(Long id) {
        Doctor doctor = new Doctor();
        doctor.setId(id);
        doctor.setRole(4l);
        return doctorMapper.updateById(doctor);
    }


}
